// 用于移动依赖注入
const buildConfig = require('../../seeyonBuild');
console.log(buildConfig, 'm');


var version = `?buildversion=${new Date().getTime()}`;
var wap = {
    script: "",
    js: [
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp-i18n.js${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp.js${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp-listView.js${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp-imgCache.js${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp-picker.js${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/js/cmp-dtPicker.js${version}`
    ],
    css: [
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/css/cmp.css${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/css/cmp-listView.css${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/cmp/css/cmp-picker.css${version}`,
        `${buildConfig.pathResolve.ctxPath}/m3/apps/v5/cap4/css/iconfont.css${version}`
    ]
}

var native = {
    script: "",
    js: [
        'http://cmp/v1.0.0/css/cmp.css',
        'http://cmp/v1.0.0/css/cmp-picker.css',
        'http://cmp/v1.0.0/css/cmp-listView.css',
        'http://cap4.v5.cmp/v1.0.0/css/iconfont.css'
    ],
    css: [
        'http://cmp/v1.0.0/js/cmp-i18n.js',
        'http://cmp/v1.0.0/js/cordova/__CMPSHELL_PLATFORM__/cordova.js',
        'http://cmp/v1.0.0/js/cordova/cordova-plugins.js',
        'http://cmp/v1.0.0/js/cmp.js',
        'http://cmp/v1.0.0/js/cmp-listView.js',
        'http://cmp/v1.0.0/js/cmp-webviewListener.js',
        'http://collaboration.v5.cmp/v/collaboration_m_api.s3js'
    ]
}

function V5Plugin() {
    // 本地运行默认读取wap配置
    let cpWap = JSON.parse(JSON.stringify(wap));
    cpWap.wap = wap;
    cpWap.native = native
    this.v5options = cpWap;
}

V5Plugin.prototype.apply = function (compiler) {
    var v5options = this.v5options;
    compiler.plugin(`compilation`, function (compilation) {
        compilation.plugin(`html-webpack-plugin-before-html-generation`, function (htmlPluginData, callback) {
            htmlPluginData.plugin.options.v5options = v5options;
        });
    });
};

module.exports = V5Plugin;
